java 您所在的位置:网站首页 split up to java

java

#java| 来源: 网络整理| 查看: 265

Object oriented programming is the single best idea I've ever seen in programming. But it isn't the best thing in all cases, you need a bit of programming experience to see the point of it, and a lot of people are claiming to do OOP when they're not.

If you can look up "structured programming" you'll probably find something more immediately useful. (Make sure you read about old structured programming. Old terms often get new, fancier meanings, and you don't need anything fancy yet.) This is a rather simple concept about breaking your program down into subroutines, which is a lot easier than breaking it down into objects. The idea is your main program is a short routine that calls subroutines ("methods" in Java) to do the work. Each subroutine only knows what it's told by its parameters. (One of those parameters might be a file name, so you can cheat a bit.) So looking at the heading of a subroutine/method gives you a quick idea of what it does, and knowing what the methods in the main program do let you see what it does almost at a glance.

Then all the subroutines are broken down similarly till a few lines of code without any method calls will do the job. A main program that calls a few methods, each of which calls a few methods, each of which.... Down to small simple methods that do the work. In this way, you can look at any part of a very large program (or small program) and quickly understand what it does.

Java is very specifically designed for people who are writing Object Oriented code. But even the most intense OO program uses some structured programming, and you can always subvert any language. (I did OO in plain C.) So you can do SP, or anything else, in Java. Forget classes and focus on big methods that can be broken down into small, managable ones. I should add that SP helps a lot with letting you reuse your code, and also with the DRY (google it, but it means "Don't Repeat Yourself") principle.

Hopefully I've explained why and how to split up your code into multiple parts without bringing in "classes". They're a great idea and are just the thing for games and Java's a great language for OOP. But it's better to know why you're doing what you're doing. Leave OOP alone until it starts to make some sense to you.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有